keep RichText formatting when parsing a string

I have two modules s (source), o (target). The source can have multiple links to the target module and each link stands for some definition of a word contained in the source object text.

For a given object I am going through each link and replacing the defined value in the source text into a dxl layout column but am not sure how to deal with the RichText. It works for normal text, but am not sure how to maintain the rich text. what i have so far is shown below...
 

setCacheState_ on;
 
Link l
 
string reqText = null;
int max, startSearchIndex, index;
startSearchIndex =0;
bool firstTimeInLoop = true;
 
//go through every link 
for l in obj->"has classified values in" do 
{
    string mn = fullName(target l);
        if (!attemptDisplay mn) continue
        Object o = target l;
        Object s = source l;
 
        Module m;
        if (null o)
        {
                m = read(mn, false);
                o = target l;
                s = source l;
        }
        
        string dictHeading = o."Object Heading";
        string dictText = o."Object Text";    
        
        if(firstTimeInLoop)
        {             
                reqText = richText(s."Object Text" "");
        }
        
        max = length(reqText);
        
        Buffer b = create();
        b = reqText;
        index = contains(b, dictHeading, 0)
        delete (b);
        
        if(index == -1)
        {             
                print "Word not found in dictionary: " dictHeading "\n";
        }
        else
        {
                print "Beginining: " reqText[0:index-1] "\n";
                print "Middle: " dictText "\n";
                print "Last: " reqText[index+SYS_ID_LENGTH:max] "\n";               
                
                string b1 = reqText[0:index-1] dictText;
                b1 = b1 reqText[index + SYS_ID_LENGTH:max]
                
                print "Sentence: " b1 "\n"; //Correctly displays the sentence.
                //need to save the replaced value in the sentence, 
and then
                reqText = b1;   
        
                startSearchIndex = index + SYS_ID_LENGTH;
                
        }
        firstTimeInLoop = false;
}
display richText(reqText)
 
        
setCacheState_ off

lsand - Fri Oct 22 18:50:11 EDT 2010

Re: keep RichText formatting when parsing a string
lsand - Fri Oct 22 18:54:50 EDT 2010

I was editing the above and my fingers got "trigger happy"..corrections are made below:

setCacheState_ on;
 
Link l
 
string reqText = null;
int max, index;
bool firstTimeInLoop = true;
 
//go through every link 
for l in obj->"has classified values in" do 
{
    string mn = fullName(target l);
        if (!attemptDisplay mn) continue
        Object o = target l;
        Object s = source l;
 
        Module m;
        if (null o)
        {
                m = read(mn, false);
                o = target l;
                s = source l;
        }
        
        string dictHeading = o."Object Heading";
        string dictText = o."Object Text";    
        
        if(firstTimeInLoop)
        {             
                reqText = richText(s."Object Text" "");
        }
        
        max = length(reqText);
        
        Buffer b = create();
        b = reqText;
        index = contains(b, dictHeading, 0)
        delete (b);
        
        if(index == -1)
        {             
                print "Word not found in dictionary: " dictHeading "\n";
        }
        else
        {
                print "Beginining: " reqText[0:index-1] "\n";
                print "Middle: " dictText "\n";
                print "Last: " reqText[index+SYS_ID_LENGTH:max] "\n";               
                
                string b1 = reqText[0:index-1] dictText;
                b1 = b1 reqText[index + SYS_ID_LENGTH:max]
                
                print "Sentence: " b1 "\n"; //Correctly displays the sentence.
                //need to save the replaced value in the sentence, 
                //and proceed to the next link
                reqText = b1;   
        
                
                
        }
        firstTimeInLoop = false;
}
display richText(reqText)
 
        
setCacheState_ off